Figure 17.19
Customer information is
displayed in a child form.
Creating the Search Form
As you look up customer records, you need a search form to allow the user to enter a name to find. The search form can be very simple, consisting of a label, a text box to enter the name, and two command buttons to perform or cancel the search. The code for the form is also very simple. If you proceed with the search, the code uses the FindFirst method of the recordset that contains the contact information to locate the first name corresponding to the desired search information. The complete search form is shown in Figure 17.20, and the code for the form is shown in Listing 17.3.
A recordset is a special type of object that acts as a link between a Visual Basic program and information stored in a database. You learn about recordsets in Chapter 26, "Using Data Access Objects (DAO)."
See "Deciding Which Recordset Type to Use," p. 569
Figure 17.20
You can make the search
form more complex by adding
a First Name search as well.
Listing 17.3 SEARCH.TXTUse the FindFirst Method to Locate the Desired Customer
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdSearch_Click()
Dim SrchStr As String
SrchStr = txtSearch.Text
CustRset.FindFirst "LastName = '" & SrchStr & "'"
Unload Me
End Sub